package club;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;

public class output {

    // 导出社团数据到指定的TXT文件
    public static void exportClubDataToTXT(club club, String filename) {
        try (PrintWriter writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(filename), StandardCharsets.UTF_8))) {
            writer.println("社团名称: " + club.getName()); // 打印社团名称

            // 打印社团的所有部门和成员
            for (Department department : club.getDepartments()) {
                writer.println("  部门名称: " + department.getName());
                for (Member member : department.getMembers()) {
                    writer.println("    成员姓名: " + member.getName());
                    writer.println("    学号: " + member.getStudentId());
                }
            }
            System.out.println("社团数据已导出到文件 " + filename);
        } catch (IOException e) {
            System.out.println("导出社团数据时发生错误: " + e.getMessage());
        }
    }
}
